package cn.blbsz.shop.utils;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回数据
 * Created by yipingdong on 2017/4/14.
 */
@Data
@NoArgsConstructor
public class R<T> {
    private static final long serialVersionUID = 1L;

    private static final Integer OK = 0;
    private static final Integer ERROR = 100;

    private Integer code;
    private String message;
    private T data;

    public R(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static R ok() {
        return new R(OK, null, null);
    }

    public static R ok(String message) {
        return new R(OK, message, null);
    }

    public R data(T data){
        this.data = data;
        return this;
    }

    public static R error() {
        return new R(ERROR, "未知异常，请联系客服", null);
    }

    public static R error(String message) {
        return new R(ERROR, message, null);
    }

}